home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-01-05 | 14.9 KB | 336 lines | [TEXT/CWIE] |
- 14dec95
-
- ScreenLight Module Interface
- Working Draft
-
- OverView
-
- ScreenLight is a ScreenSaver. Although the application shows graphics modules of
- all styles, a few points are worth mentioning:
-
- Support of Macintosh Environments
-
- The following is a breakdown of importance for various Macintosh environments:
-
- PowerPC
- ************************************ (color)
- ********************* (b&w)
-
- 68k/FPU
- *********************** (color)
- ********************* (b&w)
-
- 68k w/o FPU
- ****** (color)
- **** (b&w)
-
- Notes:
- PowerPC is the most important environment to support under ScreenLight.
- The PowerPC has lots of horsepower !! Modules may choose to run
- as PowerPC native only, which is fully supported by ScreenLight. It is
- encouraged, however, to compile a version for the 68k family as well.
-
- B&W Support means that if a monitor is set to 1 bit, that the graphics module
- understands how to draw correctly to get a desired effect.
-
- Single bit video has a certain kind of appeal for many computer users. Cognitive
- psychology studies have shown that information is clearly and rapidly represented
- on a B&W display. B&W monitors emit less EMF radiation and may be less harmful
- to the computer user over time. Although the market has largely embraced
- color computers, there will always be support for B&W on the Macintosh computer.
- Also, for those that have been around for a while, fond memories of a first
- experience with Macintosh include that old B&W display.
-
- The Macintosh Quadra series offers serious performance for many Macintosh
- users. Also, due to the number of Macintoshes sold, there is a substantial
- base of Quadra and Macintosh II, particularly Mac IIci, users out there. Many
- graphics modules run very well under this environment.
-
- Because of the strong emphasis on supporting B&W under ScreenLight, the B&W ratings
- for PowerPC, Mac 68k/FPU and color 68k/FPU are roughly on par.
-
- The Performa line of computers has enjoyed a wide commercial success. With the
- 68LC040, and some models like the IIsi and LC series, there are many Macs
- without FPU co-processors. ScreenLight will ship with several modules which run on
- these machines, but authors are encouraged to support the PowerPC first.
- It's important to note that with small changes, many graphics algorithms will
- run very well on machines w/o Floating Point. So if your module is close to running
- w/o FPU support, consider making the effort to eliminate FPU instructions and produce
- an 'FPU clean' module!
-
- Note that B&W support does _not_ mean the 68000 processor. The time for commercial
- products that support the original Macintosh, for better or for worse, has
- largely passed. Note that in the PC World, the life expectancy of a CPU is about
- 18 _months_, while here we are talking about machines that are at least 7 years
- old !
-
-
- Aesthetics Notes - "Less is More" :
-
- As a ScreenSaver, the idea is to light as few pixels as possible ! Many
- ScreenSaver modules, in an effort to broaden their scope, have elected to fill
- screen with bright colors and sharp, glaring content. Consider for a moment the
- effect of your ScreenSaver module. Most modules need to give a good first
- impression - that is when the user clicks on a Module _something_ should happen.
- But over time the user will be more likey to be concentrating on other tasks,
- passing by in a hallway, or genuinely concerned with saving the screen! So when
- designing a module, consider using fewer pixels, less bright colors. Attractive
- motion and timing can substitute for bright, galring effects to make a great
- ScreenLight module.
-
- Having said this, a few of the ScreenLight Modules already break these rules.
- So Be It. To make Great Graphics, freedom and creativity are encouraged. So
- do what you will, and make great ScreenLight Modules !
-
-
-
- -----------------------------------------------------------------
- 0) Module Resources
-
- kFPU
-
- If a 68k Module requires an FPU, you must include a resource of type 'kFPU'.
- That way the App can filter out FPU modules on machines w/o
- Floating Point support. At the very least, check for an FPU in your
- CheckRequiredFeatures() call. Note that by turngin off '-881 code' in
- your development system, you will get a compatible code module, but
- performace is likely to be very slow compared to FPU instructions.
- Check your development system for more details.
-
-
- icl8/ICN#
-
- If present, the Application uses a custom resource Icon (#-16455)
- in the Module Picker. Try to supply both the icl8 (color) and
- ICN# (B&W + mask). The resources are made in a pair automatically
- with a Resource Editor like Resorcerer.
-
-
- SS-m
-
- The module code for a 68k module is stored in a resource of type 'SS-m',
- created by your development system. Typically the resource is of ID 0,
- although this is not required.
-
-
- Control Templates
-
- The App supplies a number of templates (type TMPL) for defining your own
- custom controls. See example code for usage in the Module. Basically,
- a control is defined for each occurance of a resource from a given type.
- For instance, if you have 2 resources of type 'cCHK', your module will
- have 2 check boxes in the Application interface. Each control is given a
- UniqueID by you in the Module Control resource. When you recieve a Module
- Control-related msg, your code checks the UniqueID to find out which control
- the msg is for. etc..
-
-
- -----------------------------------------------------------------
- 1) Module Calling Conventions
-
- A Module is called with a single, identical parameter at each
- entry point, the standard Module ParamBlk. Currently, the ParamBlk
- looks like this:
-
- struct ModuleParamBlk {
- GrafPtr mGraf;
- ModuleProcs mProcs;
- FSSpec mSpec;
- short mResRefNum;
- long mStorage;
- Boolean mInPreview;
- long mInfo;
- };
-
- Here are each of the fields, defined:
-
- GrafPtr mGraf;
- the GrafPort in which you will draw. This is either a small window,
- while the Module is in Preview mode, or it is a window covering all
- GDevices on the machine, in ScreenSaving mode. The Port is color on
- any machine which supports CGrafPorts/CQD.
-
- ModuleProcs mProcs;
- a struct containing UPPs to all of the Module's entry points, used by
- the App to call the Module. By convention, the Module fills out this
- recordby calling the standard Module support routine
- InitmProcs() on ModOpen. No other action is needed by the Module.
-
- FSSpec mSpec;
- An FSSpec to the module itself. You may use the FSSpec for
- additional operations on your Module or other files.
-
- short mResRefNum;
- Your Module's resource refnum. Although you are the current resource
- in the resource chain when you are called, the App uses this refnum
- to maintain the Module ControlRec structures in the Module's resource
- fork.
-
- long mStorage;
- A Module-defined pointer to storage. Almost any module will
- want some kind of storage. This is typically used to point
- to a struct defined privately by the Module. If the Module allocates
- storage, the Module is responsible for de-allocating the storage,
- and setting the mStorage field back to 0 on ModClose().
-
- Boolean mInPreview;
- A Boolean flag which tells the Module if the Preview mode is in effect.
- Some Module may wish to substantially alter their behavior for the
- Preview mode, as there is less time given for ModDraw calls, and the
- display window is of limited, but fixed, size.
-
- long mInfo;
- Used in the ModChangePrefs() call to hold a handle to the Module
- ControlRec data. Your Module is passed a resource handle to your
- defined Module controls, one at a time. As described below, these
- handles are not Toolbox handles, but rather handles to the Standard
- Control Type structs as defined in ModuleAPI.h.
-
- In the ModAbout() call, the mInfo field holds a pointer to an EventRecord
- describing the click that called Module About. The Module can use the
- 'modifiers' field to look for special key combinations, etc.
-
-
- 2) Module Entry Points
-
- Currently, here are the Module Entry Points:
-
- OSErr ModOpen ( ModuleParamBlkPtr mpPtr);
- OSErr ModDraw ( ModuleParamBlkPtr mpPtr);
- OSErr ModClose ( ModuleParamBlkPtr mpPtr);
- OSErr ModAbout ( ModuleParamBlkPtr mpPtr);
- OSErr ModChangePrefs ( ModuleParamBlkPtr mpPtr);
-
- Here are each of the Entry Points, defined:
-
- ModOpen
- Each time the Module is initialized, the Module gets the ModOpen
- call. Consider this a complete start of your module. In practice,
- when ScreenLight changes the Module from Preview to ScreenSaving
- and back, a Close and Open pair is given. For simplicity, the Module
- completely closes and completely re-opens each time this happens.
-
- There are several standard actions which a Module typically takes.
-
- * Call InitmProcs() to fill out the UPP record.
- * Check that the machine is satisfactory to run this Module.
- eg. Color, an FPU, 68020 instruction set, etc. Some checking for
- the machine type is done by ScreenLight, but it is the final
- responsibility of the Module to check for features.
- * Check the Preview mode and make any adjustments necessary for
- the Module action.
- * Allocate your storage. If your allocation fails, return an error,
- or make appropriate adjustments. Store the pointer to the allocation
- in the mStorage field of the ModuleParamBlk.
-
- You can always return an error if initialization fails. If you do return
- an error, your ModClose() call will NOT be called.
-
-
- ModDraw
- The port is set for you on entry. If drawing or drawing calculations take
- a long time (subjectively defined), break the code into pieces to be
- executed a part each call. When in ScreenSaver mode, the draw calls are
- as fast as performance permits - in Preview Mode the time between Draw
- calls may be significantly longer (per WaitNextEvent)
-
- Some routines are supplied in ModuleRoutines.c to help with basic tasks
- like color ramping and random number generation.
-
- In your global storage define any drawing variables, offscreen buffers,
- settings, etc to control drawing. The contents of these variables will
- change only at ModChangePrefs() time, so your ModDraw() call can assume
- that the values are constant and correct. NOTE: if you need to re-init
- your graphics due to a change in a global, the right time to do this is
- in response to the ModChangePrefs() call. It is up to your own code to
- decide whether a re-init is needed. For example, if a check box boolean
- is 'Use Color', and your GWorlds have been init'd as B&W, then a complete
- re-init of your GWorlds is called for by a change to the value of the
- 'Use Color' Boolean. It is up to the ModChangePrefs() code to call for
- this re-init.
-
- The Application sets certain GrafPort variables for you on entry to your
- Module. For instance, when copying from a GWorld to an onScreen GrafPort,
- you must set ForeColor( blackColor)/BackColor( whiteColor) or you may
- get unexpected results. Since this is such a common case, the Application
- sets the ForeColor and BackColor each time Draw() is called. In general,
- set the Pen, Colors, Patterns and other Port variables each time your
- Draw routine is called.
-
-
- ModClose
- Dispose of your own storage. No changes are needed to the machine, the
- GrafPort, or the state of your Settings. Specifically your module's
- resource fork and file will be closed properly by the Application.
-
-
- ModAbout
- Do your 'About Box'! A default proc is supplied by the Application,
- which draws a PICT 128 or Styled Text 128 if present in your Module.
- To Supply your own About proc, fill out your own About proc as shown
- in the example module code.
-
- On entry you will get the ModuleParamBlkRec, with the mInfo field
- pointing to an EventRecord describing the users click in the Pickers
- 'Info Module Title' field. Command and option keys, etc, can be detected
- using the 'modifiers' field of the Event Record. If your About box
- waits for the user to given input before continuing, call WaitNextEvent()
- with an event mask of mDownMask+keyDownMask as shown in the example code.
-
-
- ModChangePrefs
- You will be passed a handle in mInfo to one of the standard Module
- ControlRec structures listed in Appendix A. Controls are of one of
- the following types: kSliderCntl, kButtonCntl, kCheckBoxCntl, kListCntl,
- kStaticStrCntl. (the List is a popupMenu) Your Module defines
- controls by creating resources with a resource editor and including these
- resource in your Module. The Application then draws controls based on
- these resources, handles interaction with the user and notifies you
- when any control values have changed.
-
- On entry, read the first long of the handle contents to determine the ID
- of the control. This Unique ID is assigned by you when creating the
- Module's resources. Based on the ID and Control Type, you can then extract
- the current value of the control information being passed, modify your
- globals in your private storage area, and take any further action required
- to set up for the next ModDraw() call.
-
-
- 3) Known Gotcha's
-
- GWorlds
- I have seen GWorlds with the 'tempMem' flag set allocate their space
- in the Application heap. Since the App heap is of limited size, big
- GWorlds may fail.
-
- TempMem
- If you are using MFNewHandleTemp(), MFMaxMem(), etc to allcoate space
- for your Module, be sure to deallocate these blocks on Close. For most
- allocations, quitting the application restores the state of the machine.
- Not so with MFTemp allocations! Your memory will be lost until the mac
- restarts ! Don't forget to deallocate temporary memory allocations.
-
- FPUs
- Be very careful about turning the -881 flag on in 68k projects. If you
- accidently create FPU instructions in your module, and do not include
- a 'kFPU' resource or check in 'CheckRequiredFeatures()' on ModOpen(),
- you will crash the machine ! For instance, using a utility routine
- which uses floating point may cause this to happen. If the -881 flag
- is off, the generated code will call SANE, which is slow and very precise,
- but the code is safe on all machines.
-
- Patterns
- In Color QuickDraw, the meaning of the old patterns has changed in an
- important way. the 'white' pattern means "completely background color',
- and black means 'completely Foreground color'. So if you set your
- background color to black, and use FillRect( r, white), guess what
- happens.
-
- As of this writing, I've seen bugs when attempting to use the qd globals.
- (probably my fault) As a work-around, just declare a variable of type
- Pattern, and init it to the desired value (black, white, gray, etc).
- See the 'Dots' example code for details.
-
-
- //************************************************************************************
-